#include "LayoutLibrary.h"
#include "Exception.h"

//Layouts
#include "exampleLayout.h"
#include "binarytreeLayout.h"
#include "edaStruct.h"
#include "GridLayout.h"
#include "LinkedListLayout.h"
//////////////////////////////////////////////////////////////////////////
using namespace std;


LayoutLibrary* LayoutLibrary::_LayoutLib = NULL;

LayoutLibrary::LayoutLibrary(void)
{
	BaseLayout* layout1 = new exampleLayout();
	BaseLayout* btreelayout = new binarytreeLayout();
	BaseLayout* edastruct = new edaStruct();
	BaseLayout* gridLayout = new GridLayout();
	BaseLayout* linklistlayout = new LinkedListLayout();
	_LayoutList.push_back(layout1);
	_LayoutList.push_back(btreelayout);
	_LayoutList.push_back(edastruct);
	_LayoutList.push_back(gridLayout);
	_LayoutList.push_back(linklistlayout);

	for(int i=0; i<_LayoutList.size();++i)
	{
		_LayoutList.at(i)->initialize();
	}

}

LayoutLibrary* LayoutLibrary::getInstance()
{
	if (_LayoutLib == NULL) 
		_LayoutLib = new LayoutLibrary();
	return _LayoutLib;
}

void LayoutLibrary::AppendLayout(BaseLayout* layout)
{
	_LayoutList.push_back(layout);
}

void LayoutLibrary::AppendSetedLayout(BaseLayout* layout)
{
	_setedLayoutList.push_back(layout);
}

vector<BaseLayout*> LayoutLibrary::getLayoutList()
{
	return _LayoutList;
}

void LayoutLibrary::doLayout()
{
	//avoid layout programer do some bad thing
	for(int i=0;i<_setedLayoutList.size();++i)
	{
		try{
			_setedLayoutList.at(i)->doLayout();
		}
		catch(...){

		}
	}


}